package com.fw.ui.view.profile.merchant.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.vaadin.dialogs.ConfirmDialog;

import com.fw.service.bean.EntryBean;
import com.fw.service.bean.ErrorBean;
import com.fw.service.file.bean.FileBean;
import com.fw.service.merchantprofile.bean.MerchantProfileBean;
import com.fw.ui.ApplicationUI;
import com.fw.ui.bao.FileBAO;
import com.fw.ui.bao.MasterDataBAO;
import com.fw.ui.bao.MerchantProfileBAO;
import com.fw.ui.bao.MessageBAO;
import com.fw.ui.bao.PropertyBAO;
import com.fw.ui.bean.merchantprofile.EditMerchantProfileTableItemBean;
import com.fw.ui.util.SessionInfoUtils;
import com.fw.ui.util.UICommonUtils;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.common.ConfirmDialogWindow;
import com.fw.ui.view.common.TablePanel;
import com.fw.ui.view.common.util.ImageStreamSource;
import com.fw.ui.view.common.util.TableHeaderProperty;
import com.fw.ui.view.event.AbstractButtonClickListener;
import com.fw.ui.view.profile.EditMerchantProfileView;
import com.fw.util.DataUtils;
import com.vaadin.data.util.BeanItem;
import com.vaadin.server.StreamResource;
import com.vaadin.server.Sizeable.Unit;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Table.Align;

@Component
@Scope(SCOPE_PROTOTYPE)
public class EditMerchantProfileSaveButtonClickListener extends AbstractButtonClickListener {

    private static Logger log = Logger.getLogger(EditMerchantProfileSaveButtonClickListener.class.getName());
    private static final long serialVersionUID = 1L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;
    @Autowired
    private MerchantProfileBAO merchantProfileBAO;
    @Autowired
    private MasterDataBAO masterDataBAO;
    @Autowired
    private PropertyBAO propertyBAO;
    @Autowired
    private MessageBAO messageBAO;
    @Autowired
    private UICommonUtils uiCommonUtils;
    @Autowired
    private FileBAO fileBAO;
    @Autowired
    private SessionInfoUtils sessionInfoUtils;

    @Autowired
    protected TablePanel tablePanel;
    private TableHeaderProperty hLabel = new TableHeaderProperty();
    private TableHeaderProperty hOldValue = new TableHeaderProperty();
    private TableHeaderProperty hNewValue = new TableHeaderProperty();

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public Map<String, Object> click(ClickEvent event) throws Exception {

	final Map<String, Object> result = new HashMap<String, Object>();
	final EditMerchantProfileView editMerchantProfileView = (EditMerchantProfileView) this.getBasedComponent();

	String title = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.message.confirm.title");
	String okCaption = messageBAO.getMessage("application.button.ok.caption");
	String cancelCaption = messageBAO.getMessage("application.button.cancel.caption");

	// String merchantId = editMerchantProfileView.getTxtMerchantId().getValue();
	String merchantStatus = (String) editMerchantProfileView.getCbbStatus().getValue();
	String merchantNameTh = editMerchantProfileView.getTxtMerchantNameTh().getValue();
	String merchantNameEn = editMerchantProfileView.getTxtMerchantNameEn().getValue();
	String companyNameEn = editMerchantProfileView.getTxtCompanyNameEn().getValue();
	String companyNameTh = editMerchantProfileView.getTxtCompanyNameTh().getValue();
	// String merchantServiceType = (String) editMerchantProfileView.getCbbMerchantServiceType().getValue();
	// String mccCode = (String) editMerchantProfileView.getCbbMCCCode().getValue();
	String statementName = editMerchantProfileView.getTxtStatementName().getValue();
	String businessRegNumber = editMerchantProfileView.getTxtBusinessRegistrationNumber().getValue();
	String countryRegion = (String) editMerchantProfileView.getCbbCountryRegion().getValue();
	String countryDomicile = (String) editMerchantProfileView.getCbbCountryDomicile().getValue();
	String mailingAddress = editMerchantProfileView.getTxtMailingAddress().getValue();
	String businessAddress = editMerchantProfileView.getTxtBusinessAddress().getValue();
	String faxNumber = editMerchantProfileView.getTxtFaxNumber().getValue();
	String url = editMerchantProfileView.getTxtUrl().getValue();
	String enquiryNumber = editMerchantProfileView.getTxtEnquiryNumber().getValue();
	String taxId = editMerchantProfileView.getTxtTaxId().getValue();
	Boolean isTestMerchant = editMerchantProfileView.getCbIsTestMerchant().getValue();

	String contact1Name = editMerchantProfileView.getTxtProjectContactName().getValue();
	String contact1Mobile = editMerchantProfileView.getTxtProjectContactMobile().getValue();
	String contact1Email = editMerchantProfileView.getTxtProjectContactEmailAddress().getValue();
	String contact1Phone = editMerchantProfileView.getTxtProjectContactPhone().getValue();

	String contact2Name = editMerchantProfileView.getTxtOperationContactName().getValue();
	String contact2Mobile = editMerchantProfileView.getTxtOperationContactMobile().getValue();
	String contact2Email = editMerchantProfileView.getTxtOperationContactEmailAddress().getValue();
	String contact2Phone = editMerchantProfileView.getTxtOperationContactPhone().getValue();

	String contact3Name = editMerchantProfileView.getTxtTechnicalContactName().getValue();
	String contact3Mobile = editMerchantProfileView.getTxtTechnicalContactMobile().getValue();
	String contact3Email = editMerchantProfileView.getTxtTechnicalContactEmailAddress().getValue();
	String contact3Phone = editMerchantProfileView.getTxtTechnicalContactPhone().getValue();

	String contact4Name = editMerchantProfileView.getTxtFinancialContactName().getValue();
	String contact4Mobile = editMerchantProfileView.getTxtFinancialContactMobile().getValue();
	String contact4Email = editMerchantProfileView.getTxtFinancialContactEmailAddress().getValue();
	String contact4Phone = editMerchantProfileView.getTxtFinancialContactPhone().getValue();

	final MerchantProfileBean oldMerchantProfileBean = editMerchantProfileView.getMerchantProfileBean();
	final MerchantProfileBean merchantProfileBean = new MerchantProfileBean();
	BeanUtils.copyProperties(oldMerchantProfileBean, merchantProfileBean);
	// merchantProfileBean.setMerchantId(merchantId);
	merchantProfileBean.setMerchantStatus(merchantStatus);
	merchantProfileBean.setMerchantNameEn(merchantNameEn);
	merchantProfileBean.setMerchantNameTh(merchantNameTh);
	merchantProfileBean.setCompanyNameEn(companyNameEn);
	merchantProfileBean.setCompanyNameTh(companyNameTh);
	// merchantProfileBean.setMerchantServiceType(merchantServiceType);
	// merchantProfileBean.setMccCode(mccCode);
	merchantProfileBean.setStatementName(statementName);
	merchantProfileBean.setBusinessRegNumber(businessRegNumber);
	merchantProfileBean.setCountryRegion(countryRegion);
	merchantProfileBean.setCountryDomicile(countryDomicile);
	merchantProfileBean.setMailingAddress(mailingAddress);
	merchantProfileBean.setBusinessAddress(businessAddress);
	merchantProfileBean.setFaxNumber(faxNumber);
	merchantProfileBean.setUrl(url);
	merchantProfileBean.setEnquiryNumber(enquiryNumber);
	merchantProfileBean.setTaxId(taxId);

	merchantProfileBean.setContact1Name(contact1Name);
	merchantProfileBean.setContact1Mobile(contact1Mobile);
	merchantProfileBean.setContact1Email(contact1Email);
	merchantProfileBean.setContact1Phone(contact1Phone);

	merchantProfileBean.setContact2Name(contact2Name);
	merchantProfileBean.setContact2Mobile(contact2Mobile);
	merchantProfileBean.setContact2Email(contact2Email);
	merchantProfileBean.setContact2Phone(contact2Phone);

	merchantProfileBean.setContact3Name(contact3Name);
	merchantProfileBean.setContact3Mobile(contact3Mobile);
	merchantProfileBean.setContact3Email(contact3Email);
	merchantProfileBean.setContact3Phone(contact3Phone);

	merchantProfileBean.setContact4Name(contact4Name);
	merchantProfileBean.setContact4Mobile(contact4Mobile);
	merchantProfileBean.setContact4Email(contact4Email);
	merchantProfileBean.setContact4Phone(contact4Phone);

	merchantProfileBean.setIsTestMerchant(isTestMerchant);

	this.tablePanel.init();
	// set table
	this.hLabel.setColumnName(this.messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.header.label"));
	this.hOldValue.setColumnName(this.messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.header.oldValue"));
	this.hNewValue.setColumnName(this.messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.header.newValue"));

	this.hLabel.setColumnId("label");
	this.hLabel.setType(String.class);
	this.hLabel.setAlignment(Align.LEFT);
	this.hLabel.setDefaultValue(null);
	this.hLabel.setIconResource(null);
	this.hLabel.setOrder(1);

	this.hOldValue.setColumnId("oldValue");
	this.hOldValue.setType(String.class);
	this.hOldValue.setAlignment(Align.CENTER);
	this.hOldValue.setDefaultValue(null);
	this.hOldValue.setIconResource(null);
	this.hOldValue.setOrder(2);

	this.hNewValue.setColumnId("newValue");
	this.hNewValue.setType(String.class);
	this.hNewValue.setAlignment(Align.CENTER);
	this.hNewValue.setDefaultValue(null);
	this.hNewValue.setIconResource(null);
	this.hNewValue.setOrder(3);

	List<TableHeaderProperty> headerProperties = new ArrayList<TableHeaderProperty>();
	headerProperties.add(hLabel);
	headerProperties.add(hOldValue);
	headerProperties.add(hNewValue);

	this.tablePanel.setTableColumnHeader(this.hLabel.getColumnId(), this.hLabel.getColumnName());
	this.tablePanel.setTableColumnHeader(this.hOldValue.getColumnId(), this.hOldValue.getColumnName());
	this.tablePanel.setTableColumnHeader(this.hNewValue.getColumnId(), this.hNewValue.getColumnName());

	this.tablePanel.setTableBeanContainerColumnHeader(headerProperties, EditMerchantProfileTableItemBean.class);
	this.tablePanel.setTableSelect(false);
	this.tablePanel.setAllowSortRecord(false);
	this.tablePanel.setEnableTableSorting(false);
	this.tablePanel.setTableColumnReordering(false);
	// this.tablePanel.createControlTablePageNumber();

	List<BeanItem> beanItems = this.generateTableItemBean(oldMerchantProfileBean, merchantProfileBean);
	this.tablePanel.clearTableData();
	// this.tablePanel.setManualPageTable(1);
	this.tablePanel.setTableBeanContainerData(beanItems);

	tablePanel.setWidth(100, Unit.PERCENTAGE);
	tablePanel.setHeight(155, Unit.PIXELS);

	ConfirmDialogWindow.createConfirmDialog(editMerchantProfileView.getUI(), title, this.tablePanel, okCaption, cancelCaption,
		new ConfirmDialog.Listener() {
		    private static final long serialVersionUID = 1L;

		    @Override
		    public void onClose(ConfirmDialog dialog) {
			if (dialog.isConfirmed()) {

			    try {

				ApplicationUI applicationUI = (ApplicationUI) editMerchantProfileView.getUI();
				sessionInfoUtils.setSessionInfoDetails(merchantProfileBean, applicationUI.getAuthenticationBean(),
					applicationUI.getLocale());

				if (oldMerchantProfileBean.getFileExtension() != null && oldMerchantProfileBean.getContentType() != null
					&& oldMerchantProfileBean.getLogoImageByteArray() != null) {
				    try {
					FileBean fileBean = fileBAO.saveFileAndGenerateFilename(oldMerchantProfileBean.getFileExtension(),
						oldMerchantProfileBean.getContentType(), oldMerchantProfileBean.getLogoImageByteArray(),
						"Merchant Logo");
					if (fileBean != null && fileBean.getId() != null) {
					    // delete if have logo id
					    if (oldMerchantProfileBean.getLogoId() != null) {
						try {
						    fileBAO.deleteFile(oldMerchantProfileBean.getLogoId());
						} catch (Exception e) {
						    log.error(e, e);
						}
					    }
					    // set new logo id
					    merchantProfileBean.setLogoId(fileBean.getId());
					}
				    } catch (Exception e) {
					log.error(e, e);
				    }
				}
				log.debug("old logoId = " + oldMerchantProfileBean.getLogoId());
				log.debug("new logoId = " + merchantProfileBean.getLogoId());
				Map<String, Serializable> mapResult = merchantProfileBAO.updateMerchantProfile(merchantProfileBean);
				if (mapResult != null) {
				    List<ErrorBean> errorBeans = (List<ErrorBean>) mapResult.get(List.class.getName() + "."
					    + ErrorBean.class.getName());
				    MerchantProfileBean resultMerchantProfileBean = (MerchantProfileBean) mapResult
					    .get(MerchantProfileBean.class.getName());
				    if (errorBeans != null && !errorBeans.isEmpty()) {
					result.put(MessageBAO.MESSAGE_WARNING_TYPE, errorBeans);
				    } else {
					if (resultMerchantProfileBean != null && resultMerchantProfileBean.getId() != null) {
					    log.debug("result logoId = " + resultMerchantProfileBean.getLogoId());
					    editMerchantProfileView.setMerchantProfileBean(resultMerchantProfileBean);
					    if (resultMerchantProfileBean.getLogoId() != null) {
						try {
						    FileBean resultFileBean = fileBAO.getFile(resultMerchantProfileBean.getLogoId());
						    if (resultFileBean != null) {
							editMerchantProfileView.getLayoutLogo().setWidthUndefined();
							editMerchantProfileView.getLayoutLogo().setHeightUndefined();
							editMerchantProfileView.getLblMerchantLogoHint().setVisible(false);
							editMerchantProfileView.getImgMerchantLogo().setVisible(true);
							ImageStreamSource imageStreamSource = new ImageStreamSource();
							imageStreamSource.setBytes(resultFileBean.getContent());
							StreamResource imagesource = new StreamResource(imageStreamSource, resultFileBean
								.getFilename());
							editMerchantProfileView.getImgMerchantLogo().setSource(imagesource);
							// keep for using display in changed table
							editMerchantProfileView.getMerchantProfileBean().setOldFileName(
								resultFileBean.getFilename());
						    }
						} catch (Exception e) {
						    log.error(e, e);
						    editMerchantProfileView.getImgMerchantLogo().setSource(null);
						    editMerchantProfileView.getImgMerchantLogo().setVisible(false);
						    editMerchantProfileView.getLayoutLogo().setWidth("300px");
						    editMerchantProfileView.getLayoutLogo().setHeight("150px");
						    editMerchantProfileView.getLblMerchantLogoHint().setVisible(true);
						}
					    } else {
						editMerchantProfileView.getImgMerchantLogo().setSource(null);
						editMerchantProfileView.getImgMerchantLogo().setVisible(false);
						editMerchantProfileView.getLayoutLogo().setWidth("300px");
						editMerchantProfileView.getLayoutLogo().setHeight("150px");
						editMerchantProfileView.getLblMerchantLogoHint().setVisible(true);
					    }

					    List<EntryBean<String, String>> masterData = masterDataBAO
						    .selectMerchantProfileStatusByCurrentStatus(resultMerchantProfileBean
							    .getMerchantStatus());
					    if (masterData != null && !masterData.isEmpty()) {
						editMerchantProfileView.getCbbStatus().removeAllItems();
						for (EntryBean<String, String> entry : masterData) {
						    editMerchantProfileView.getCbbStatus().addItem(entry.getKey());
						    editMerchantProfileView.getCbbStatus().setItemCaption(entry.getKey(), entry.getValue());
						}
					    }

					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtMerchantId(),
						    resultMerchantProfileBean.getMerchantId());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getCbbStatus(),
						    resultMerchantProfileBean.getMerchantStatus());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtMerchantNameEn(),
						    resultMerchantProfileBean.getMerchantNameEn());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtMerchantNameTh(),
						    resultMerchantProfileBean.getMerchantNameTh());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtCompanyNameEn(),
						    resultMerchantProfileBean.getCompanyNameEn());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtCompanyNameTh(),
						    resultMerchantProfileBean.getCompanyNameTh());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getCbbMerchantServiceType(),
						    resultMerchantProfileBean.getMerchantServiceType());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getCbbMCCCode(),
						    resultMerchantProfileBean.getMccCode());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtBusinessRegistrationNumber(),
						    resultMerchantProfileBean.getBusinessRegNumber());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtStatementName(),
						    resultMerchantProfileBean.getStatementName());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getCbbCountryDomicile(),
						    resultMerchantProfileBean.getCountryDomicile());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getCbbCountryRegion(),
						    resultMerchantProfileBean.getCountryRegion());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtBusinessAddress(),
						    resultMerchantProfileBean.getBusinessAddress());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtMailingAddress(),
						    resultMerchantProfileBean.getMailingAddress());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtUrl(),
						    resultMerchantProfileBean.getUrl());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtFaxNumber(),
						    resultMerchantProfileBean.getFaxNumber());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtTaxId(),
						    resultMerchantProfileBean.getTaxId());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtEnquiryNumber(),
						    resultMerchantProfileBean.getEnquiryNumber());

					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtProjectContactName(),
						    resultMerchantProfileBean.getContact1Name());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtProjectContactPhone(),
						    resultMerchantProfileBean.getContact1Phone());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtProjectContactMobile(),
						    resultMerchantProfileBean.getContact1Mobile());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtProjectContactEmailAddress(),
						    resultMerchantProfileBean.getContact1Email());

					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtOperationContactName(),
						    resultMerchantProfileBean.getContact2Name());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtOperationContactPhone(),
						    resultMerchantProfileBean.getContact2Phone());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtOperationContactMobile(),
						    resultMerchantProfileBean.getContact2Mobile());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtOperationContactEmailAddress(),
						    resultMerchantProfileBean.getContact2Email());

					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtTechnicalContactName(),
						    resultMerchantProfileBean.getContact3Name());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtTechnicalContactPhone(),
						    resultMerchantProfileBean.getContact3Phone());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtTechnicalContactMobile(),
						    resultMerchantProfileBean.getContact3Mobile());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtTechnicalContactEmailAddress(),
						    resultMerchantProfileBean.getContact3Email());

					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtFinancialContactName(),
						    resultMerchantProfileBean.getContact4Name());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtFinancialContactPhone(),
						    resultMerchantProfileBean.getContact4Phone());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtFinancialContactMobile(),
						    resultMerchantProfileBean.getContact4Mobile());
					    uiCommonUtils.setValueUIComponent(editMerchantProfileView.getTxtFinancialContactEmailAddress(),
						    resultMerchantProfileBean.getContact4Email());

					    uiCommonUtils.clearAllUIComponentNoInputFieldWithPrefix(editMerchantProfileView);

					    String closeStatus = propertyBAO
						    .getPropertyValue("com.fw.ui.view.profile.EditMerchantProfileView.status.item.closed");
					    if (closeStatus.equals(resultMerchantProfileBean.getMerchantStatus())) {
						setAutoEnabled(false);
						List<com.vaadin.ui.Component> componentsEnable = new ArrayList<com.vaadin.ui.Component>();
						componentsEnable.add(editMerchantProfileView.getBtnCancel());
						uiCommonUtils.setEnableAllUIComponent(editMerchantProfileView, componentsEnable, false);
					    }

					    result.put(MessageBAO.MESSAGE_INFO_TYPE,
						    "com.fw.ui.view.profile.EditMerchantProfileView.message.updated");
					} else {
					    result.put(MessageBAO.MESSAGE_WARNING_TYPE,
						    "com.fw.ui.view.profile.EditMerchantProfileView.message.failed");
					}
				    }
				} else {
				    result.put(MessageBAO.MESSAGE_WARNING_TYPE, "message.error.common");
				}
			    } catch (Exception e) {
				result.put(MessageBAO.MESSAGE_WARNING_TYPE, "message.error.common");
			    }
			    // notification
			    notification(result);
			}
		    }
		}, "255px", "650px");

	return null;
    }

    @SuppressWarnings("rawtypes")
    private List<BeanItem> generateTableItemBean(MerchantProfileBean oldMerchantProfileBean, MerchantProfileBean merchantProfileBean) {
	EditMerchantProfileView editMerchantProfileView = (EditMerchantProfileView) this.getBasedComponent();
	List<EditMerchantProfileTableItemBean> itemBeans = new ArrayList<EditMerchantProfileTableItemBean>();
	List<BeanItem> beanItems = new ArrayList<BeanItem>();
	// process
	if (merchantProfileBean.getFileName() != null
		&& DataUtils.isChange(oldMerchantProfileBean.getOldFileName(), merchantProfileBean.getFileName())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.merchantLogo"), DataUtils
		    .stringValue(oldMerchantProfileBean.getOldFileName()), DataUtils.stringValue(merchantProfileBean.getFileName())));
	}
	// process
	if (DataUtils.isChange(oldMerchantProfileBean.getIsTestMerchant(), merchantProfileBean.getIsTestMerchant())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.isTestMerchant"), DataUtils
		    .stringValue(oldMerchantProfileBean.getIsTestMerchant()),
		    DataUtils.stringValue(merchantProfileBean.getIsTestMerchant())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getMerchantStatus(), merchantProfileBean.getMerchantStatus())) {
	    String oldValue = editMerchantProfileView.getCbbStatus().getItemCaption(oldMerchantProfileBean.getMerchantStatus());
	    String newValue = editMerchantProfileView.getCbbStatus().getItemCaption(merchantProfileBean.getMerchantStatus());
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.status"), DataUtils.stringValue(oldValue), DataUtils
		    .stringValue(newValue)));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getMerchantNameEn(), merchantProfileBean.getMerchantNameEn())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.merchantNameEN"), DataUtils
		    .stringValue(oldMerchantProfileBean.getMerchantNameEn()),
		    DataUtils.stringValue(merchantProfileBean.getMerchantNameEn())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getMerchantNameTh(), merchantProfileBean.getMerchantNameTh())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.merchantNameTH"), DataUtils
		    .stringValue(oldMerchantProfileBean.getMerchantNameTh()),
		    DataUtils.stringValue(merchantProfileBean.getMerchantNameTh())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getCompanyNameEn(), merchantProfileBean.getCompanyNameEn())) {
	    itemBeans
		    .add(new EditMerchantProfileTableItemBean(messageBAO
			    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.companyNameEN"), DataUtils
			    .stringValue(oldMerchantProfileBean.getCompanyNameEn()), DataUtils.stringValue(merchantProfileBean
			    .getCompanyNameEn())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getCompanyNameTh(), merchantProfileBean.getCompanyNameTh())) {
	    itemBeans
		    .add(new EditMerchantProfileTableItemBean(messageBAO
			    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.companyNameTH"), DataUtils
			    .stringValue(oldMerchantProfileBean.getCompanyNameTh()), DataUtils.stringValue(merchantProfileBean
			    .getCompanyNameTh())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getBusinessRegNumber(), merchantProfileBean.getBusinessRegNumber())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.businessRegistrationNumber"), DataUtils
		    .stringValue(oldMerchantProfileBean.getBusinessRegNumber()), DataUtils.stringValue(merchantProfileBean
		    .getBusinessRegNumber())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getStatementName(), merchantProfileBean.getStatementName())) {
	    itemBeans
		    .add(new EditMerchantProfileTableItemBean(messageBAO
			    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.statementName"), DataUtils
			    .stringValue(oldMerchantProfileBean.getStatementName()), DataUtils.stringValue(merchantProfileBean
			    .getStatementName())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getCountryDomicile(), merchantProfileBean.getCountryDomicile())) {
	    String oldValue = editMerchantProfileView.getCbbCountryDomicile().getItemCaption(oldMerchantProfileBean.getCountryDomicile());
	    String newValue = editMerchantProfileView.getCbbCountryDomicile().getItemCaption(merchantProfileBean.getCountryDomicile());
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.countryDomicile"), DataUtils.stringValue(oldValue),
		    DataUtils.stringValue(newValue)));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getCountryRegion(), merchantProfileBean.getCountryRegion())) {
	    String oldValue = editMerchantProfileView.getCbbCountryRegion().getItemCaption(oldMerchantProfileBean.getCountryRegion());
	    String newValue = editMerchantProfileView.getCbbCountryRegion().getItemCaption(merchantProfileBean.getCountryRegion());
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.countryRegion"), DataUtils.stringValue(oldValue),
		    DataUtils.stringValue(newValue)));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getBusinessAddress(), merchantProfileBean.getBusinessAddress())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.businessAddress"), DataUtils
		    .stringValue(oldMerchantProfileBean.getBusinessAddress()), DataUtils.stringValue(merchantProfileBean
		    .getBusinessAddress())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getMailingAddress(), merchantProfileBean.getMailingAddress())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.mailingAddress"), DataUtils
		    .stringValue(oldMerchantProfileBean.getMailingAddress()),
		    DataUtils.stringValue(merchantProfileBean.getMailingAddress())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getUrl(), merchantProfileBean.getUrl())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.url"), DataUtils.stringValue(oldMerchantProfileBean
		    .getUrl()), DataUtils.stringValue(merchantProfileBean.getUrl())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getFaxNumber(), merchantProfileBean.getFaxNumber())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.faxNumber"), DataUtils
		    .stringValue(oldMerchantProfileBean.getFaxNumber()), DataUtils.stringValue(merchantProfileBean.getFaxNumber())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getTaxId(), merchantProfileBean.getTaxId())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(messageBAO
		    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.taxId"), DataUtils.stringValue(oldMerchantProfileBean
		    .getTaxId()), DataUtils.stringValue(merchantProfileBean.getTaxId())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getEnquiryNumber(), merchantProfileBean.getEnquiryNumber())) {
	    itemBeans
		    .add(new EditMerchantProfileTableItemBean(messageBAO
			    .getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.enquiryNumber"), DataUtils
			    .stringValue(oldMerchantProfileBean.getEnquiryNumber()), DataUtils.stringValue(merchantProfileBean
			    .getEnquiryNumber())));
	}

	String prefix = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.project.text") + " ";
	String name = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.name");
	String phone = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.phone");
	String mobile = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.mobile");
	String email = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.email");
	if (DataUtils.isChange(oldMerchantProfileBean.getContact1Name(), merchantProfileBean.getContact1Name())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + name, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact1Name()), DataUtils.stringValue(merchantProfileBean.getContact1Name())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact1Phone(), merchantProfileBean.getContact1Phone())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + phone, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact1Phone()), DataUtils.stringValue(merchantProfileBean.getContact1Phone())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact1Mobile(), merchantProfileBean.getContact1Mobile())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + mobile, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact1Mobile()), DataUtils.stringValue(merchantProfileBean.getContact1Mobile())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact1Email(), merchantProfileBean.getContact1Email())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + email, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact1Email()), DataUtils.stringValue(merchantProfileBean.getContact1Email())));
	}
	// contact2
	prefix = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.operation.text") + " ";
	if (DataUtils.isChange(oldMerchantProfileBean.getContact2Name(), merchantProfileBean.getContact2Name())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + name, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact2Name()), DataUtils.stringValue(merchantProfileBean.getContact2Name())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact2Phone(), merchantProfileBean.getContact2Phone())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + phone, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact2Phone()), DataUtils.stringValue(merchantProfileBean.getContact2Phone())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact2Mobile(), merchantProfileBean.getContact2Mobile())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + mobile, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact2Mobile()), DataUtils.stringValue(merchantProfileBean.getContact2Mobile())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact2Email(), merchantProfileBean.getContact2Email())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + email, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact2Email()), DataUtils.stringValue(merchantProfileBean.getContact2Email())));
	}
	// contact3
	prefix = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.technical.text") + " ";
	if (DataUtils.isChange(oldMerchantProfileBean.getContact3Name(), merchantProfileBean.getContact3Name())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + name, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact3Name()), DataUtils.stringValue(merchantProfileBean.getContact3Name())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact3Phone(), merchantProfileBean.getContact3Phone())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + phone, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact3Phone()), DataUtils.stringValue(merchantProfileBean.getContact3Phone())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact3Mobile(), merchantProfileBean.getContact3Mobile())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + mobile, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact3Mobile()), DataUtils.stringValue(merchantProfileBean.getContact3Mobile())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact3Email(), merchantProfileBean.getContact3Email())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + email, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact3Email()), DataUtils.stringValue(merchantProfileBean.getContact3Email())));
	}
	// contact4
	prefix = messageBAO.getMessage("com.fw.ui.view.profile.EditMerchantProfileView.label.contact.financial.text") + " ";
	if (DataUtils.isChange(oldMerchantProfileBean.getContact4Name(), merchantProfileBean.getContact4Name())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + name, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact4Name()), DataUtils.stringValue(merchantProfileBean.getContact4Name())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact4Phone(), merchantProfileBean.getContact4Phone())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + phone, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact4Phone()), DataUtils.stringValue(merchantProfileBean.getContact4Phone())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact4Mobile(), merchantProfileBean.getContact4Mobile())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + mobile, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact4Mobile()), DataUtils.stringValue(merchantProfileBean.getContact4Mobile())));
	}
	if (DataUtils.isChange(oldMerchantProfileBean.getContact4Email(), merchantProfileBean.getContact4Email())) {
	    itemBeans.add(new EditMerchantProfileTableItemBean(prefix + email, DataUtils.stringValue(oldMerchantProfileBean
		    .getContact4Email()), DataUtils.stringValue(merchantProfileBean.getContact4Email())));
	}

	// create beanItems
	if (itemBeans != null && !itemBeans.isEmpty()) {
	    for (EditMerchantProfileTableItemBean editMerchantProfileTableItemBean : itemBeans) {
		beanItems.add(new BeanItem<EditMerchantProfileTableItemBean>(editMerchantProfileTableItemBean));
	    }
	}
	return beanItems;
    }

    @Override
    public boolean validate(ClickEvent event) {
	boolean validate = false;
	EditMerchantProfileView editMerchantProfileView = (EditMerchantProfileView) this.getBasedComponent();
	try {

	    uiCommonUtils.clearAllUIComponentNoInputFieldWithPrefix(editMerchantProfileView);

	    boolean merchantIdValid = editMerchantProfileView.getTxtMerchantId().isValid();
	    boolean merchantNameEnValid = editMerchantProfileView.getTxtMerchantNameEn().isValid();
	    boolean companyNameEnValid = editMerchantProfileView.getTxtCompanyNameEn().isValid();
	    boolean merchantServiceTypeValid = editMerchantProfileView.getCbbMerchantServiceType().isValid();
	    boolean businessRegistrationNumberValid = editMerchantProfileView.getTxtBusinessRegistrationNumber().isValid();
	    boolean countryDomicileValid = editMerchantProfileView.getCbbCountryDomicile().isValid();
	    boolean businessAddressValid = editMerchantProfileView.getTxtBusinessAddress().isValid();
	    boolean urlValid = editMerchantProfileView.getTxtUrl().isValid();
	    boolean taxIdValid = editMerchantProfileView.getTxtTaxId().isValid();
	    boolean isTestMerchantValid = editMerchantProfileView.getCbIsTestMerchant().isValid();
	    boolean projectContactNameValid = editMerchantProfileView.getTxtProjectContactName().isValid();
	    boolean projectContactPhoneValid = editMerchantProfileView.getTxtProjectContactPhone().isValid();
	    boolean projectContactMobileValid = editMerchantProfileView.getTxtProjectContactMobile().isValid();
	    boolean projectContactEmailAddressValid = editMerchantProfileView.getTxtProjectContactEmailAddress().isValid();
	    boolean technicalContactNameValid = editMerchantProfileView.getTxtTechnicalContactName().isValid();
	    boolean technicalContactPhoneValid = editMerchantProfileView.getTxtTechnicalContactPhone().isValid();
	    boolean technicalContactMobileValid = editMerchantProfileView.getTxtTechnicalContactMobile().isValid();
	    boolean technicalContactEmailAddressValid = editMerchantProfileView.getTxtTechnicalContactEmailAddress().isValid();

	    boolean statusValid = editMerchantProfileView.getCbbStatus().isValid();
	    boolean merchantNameThValid = editMerchantProfileView.getTxtMerchantNameTh().isValid();
	    boolean companyNameThValid = editMerchantProfileView.getTxtCompanyNameTh().isValid();
	    boolean mccCodeValid = editMerchantProfileView.getCbbMCCCode().isValid();
	    boolean statementNameValid = editMerchantProfileView.getTxtStatementName().isValid();
	    boolean countryRegionValid = editMerchantProfileView.getCbbCountryRegion().isValid();
	    boolean mailingAddressValid = editMerchantProfileView.getTxtMailingAddress().isValid();
	    boolean faxNumberValid = editMerchantProfileView.getTxtFaxNumber().isValid();
	    boolean enquiryNumberValid = editMerchantProfileView.getTxtEnquiryNumber().isValid();
	    boolean operationContactNameValid = editMerchantProfileView.getTxtOperationContactName().isValid();
	    boolean operationContactPhoneValid = editMerchantProfileView.getTxtOperationContactPhone().isValid();
	    boolean operationContactMobileValid = editMerchantProfileView.getTxtOperationContactMobile().isValid();
	    boolean operationContactEmailAddressValid = editMerchantProfileView.getTxtOperationContactEmailAddress().isValid();
	    boolean financialContactNameValid = editMerchantProfileView.getTxtFinancialContactName().isValid();
	    boolean financialContactPhoneValid = editMerchantProfileView.getTxtFinancialContactPhone().isValid();
	    boolean financialContactMobileValid = editMerchantProfileView.getTxtFinancialContactMobile().isValid();
	    boolean financialContactEmailAddressValid = editMerchantProfileView.getTxtFinancialContactEmailAddress().isValid();

	    if (merchantIdValid && merchantNameEnValid && companyNameEnValid && merchantServiceTypeValid && businessRegistrationNumberValid
		    && countryDomicileValid && businessAddressValid && urlValid && taxIdValid && isTestMerchantValid
		    && projectContactNameValid && projectContactPhoneValid && projectContactMobileValid && projectContactEmailAddressValid
		    && technicalContactNameValid && technicalContactPhoneValid && technicalContactMobileValid
		    && technicalContactEmailAddressValid && statusValid && merchantNameThValid && companyNameThValid && mccCodeValid
		    && statementNameValid && countryRegionValid && mailingAddressValid && faxNumberValid && enquiryNumberValid
		    && operationContactNameValid && operationContactPhoneValid && operationContactMobileValid
		    && operationContactEmailAddressValid && financialContactNameValid && financialContactPhoneValid
		    && financialContactMobileValid && financialContactEmailAddressValid) {
		validate = true;
	    } else {
		if (!merchantIdValid) {
		    editMerchantProfileView.getTxtMerchantId().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtMerchantId().getErrorMessage() != null) {
			editMerchantProfileView.getLblMerchantIdValidateMessage().setValue(
				editMerchantProfileView.getTxtMerchantId().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutMerchantIdValidate().setVisible(true);
		}
		if (!statusValid) {
		    editMerchantProfileView.getCbbStatus().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getCbbStatus().getErrorMessage() != null) {
			editMerchantProfileView.getLblStatusValidateMessage().setValue(
				editMerchantProfileView.getCbbStatus().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutStatusValidate().setVisible(true);
		}

		if (!merchantNameEnValid) {
		    editMerchantProfileView.getTxtMerchantNameEn().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtMerchantNameEn().getErrorMessage() != null) {
			editMerchantProfileView.getLblMerchantNameValidateMessageEn().setValue(
				editMerchantProfileView.getTxtMerchantNameEn().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutMerchantNameValidateEn().setVisible(true);
		}
		if (!merchantNameThValid) {
		    editMerchantProfileView.getTxtMerchantNameTh().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtMerchantNameTh().getErrorMessage() != null) {
			editMerchantProfileView.getLblMerchantNameValidateMessageTh().setValue(
				editMerchantProfileView.getTxtMerchantNameTh().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutMerchantNameValidateTh().setVisible(true);
		}

		if (!companyNameEnValid) {
		    editMerchantProfileView.getTxtCompanyNameEn().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtCompanyNameEn().getErrorMessage() != null) {
			editMerchantProfileView.getLblCompanyNameValidateMessageEn().setValue(
				editMerchantProfileView.getTxtCompanyNameEn().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutCompanyNameValidateEn().setVisible(true);
		}
		if (!companyNameThValid) {
		    editMerchantProfileView.getTxtCompanyNameTh().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtCompanyNameTh().getErrorMessage() != null) {
			editMerchantProfileView.getLblCompanyNameValidateMessageTh().setValue(
				editMerchantProfileView.getTxtCompanyNameTh().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutCompanyNameValidateTh().setVisible(true);
		}

		if (!merchantServiceTypeValid) {
		    editMerchantProfileView.getCbbMerchantServiceType().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getCbbMerchantServiceType().getErrorMessage() != null) {
			editMerchantProfileView.getLblMerchantServiceTypeValidateMessage().setValue(
				editMerchantProfileView.getCbbMerchantServiceType().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutMerchantServiceTypeValidate().setVisible(true);
		}
		if (!mccCodeValid) {
		    editMerchantProfileView.getCbbMCCCode().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getCbbMCCCode().getErrorMessage() != null) {
			editMerchantProfileView.getLblMCCCodeValidateMessage().setValue(
				editMerchantProfileView.getCbbMCCCode().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutMCCCodeValidate().setVisible(true);
		}

		if (!businessRegistrationNumberValid) {
		    editMerchantProfileView.getTxtBusinessRegistrationNumber().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtBusinessRegistrationNumber().getErrorMessage() != null) {
			editMerchantProfileView.getLblBusinessRegistrationNumberValidateMessage().setValue(
				editMerchantProfileView.getTxtBusinessRegistrationNumber().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutBusinessRegistrationNumberValidate().setVisible(true);
		}
		if (!statementNameValid) {
		    editMerchantProfileView.getTxtStatementName().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtStatementName().getErrorMessage() != null) {
			editMerchantProfileView.getLblStatementNameValidateMessage().setValue(
				editMerchantProfileView.getTxtStatementName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutStatementNameValidate().setVisible(true);
		}

		if (!countryDomicileValid) {
		    editMerchantProfileView.getCbbCountryDomicile().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getCbbCountryDomicile().getErrorMessage() != null) {
			editMerchantProfileView.getLblCountryDomicileValidateMessage().setValue(
				editMerchantProfileView.getCbbCountryDomicile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutCountryDomicileValidate().setVisible(true);
		}
		if (!countryRegionValid) {
		    editMerchantProfileView.getCbbCountryRegion().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getCbbCountryRegion().getErrorMessage() != null) {
			editMerchantProfileView.getLblCountryRegionValidateMessage().setValue(
				editMerchantProfileView.getCbbCountryRegion().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutCountryRegionValidate().setVisible(true);
		}

		if (!businessAddressValid) {
		    editMerchantProfileView.getTxtBusinessAddress().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtBusinessAddress().getErrorMessage() != null) {
			editMerchantProfileView.getLblBusinessAddressValidateMessage().setValue(
				editMerchantProfileView.getTxtBusinessAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutBusinessAddressValidate().setVisible(true);
		}
		if (!mailingAddressValid) {
		    editMerchantProfileView.getTxtMailingAddress().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtMailingAddress().getErrorMessage() != null) {
			editMerchantProfileView.getLblMailingAddressValidateMessage().setValue(
				editMerchantProfileView.getTxtMailingAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutMailingAddressValidate().setVisible(true);
		}

		if (!urlValid) {
		    editMerchantProfileView.getTxtUrl().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtUrl().getErrorMessage() != null) {
			editMerchantProfileView.getLblUrlValidateMessage().setValue(
				editMerchantProfileView.getTxtUrl().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutUrlValidate().setVisible(true);
		}
		if (!faxNumberValid) {
		    editMerchantProfileView.getTxtFaxNumber().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtFaxNumber().getErrorMessage() != null) {
			editMerchantProfileView.getLblFaxNumberValidateMessage().setValue(
				editMerchantProfileView.getTxtFaxNumber().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutFaxNumberValidate().setVisible(true);
		}

		if (!taxIdValid) {
		    editMerchantProfileView.getTxtTaxId().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtTaxId().getErrorMessage() != null) {
			editMerchantProfileView.getLblTaxIdValidateMessage().setValue(
				editMerchantProfileView.getTxtTaxId().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutTaxIdValidate().setVisible(true);
		}
		if (!enquiryNumberValid) {
		    editMerchantProfileView.getTxtEnquiryNumber().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtEnquiryNumber().getErrorMessage() != null) {
			editMerchantProfileView.getLblEnquiryNumberValidateMessage().setValue(
				editMerchantProfileView.getTxtEnquiryNumber().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutEnquiryNumberValidate().setVisible(true);
		}

		if (!isTestMerchantValid) {
		    editMerchantProfileView.getCbIsTestMerchant().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getCbIsTestMerchant().getErrorMessage() != null) {
			editMerchantProfileView.getLblIsTestMerchantValidateMessage().setValue(
				editMerchantProfileView.getCbIsTestMerchant().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutIsTestMerchantValidate().setVisible(true);
		}

		// project
		if (!projectContactNameValid) {
		    editMerchantProfileView.getTxtProjectContactName().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtProjectContactName().getErrorMessage() != null) {
			editMerchantProfileView.getLblProjectContactNameValidateMessage().setValue(
				editMerchantProfileView.getTxtProjectContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutProjectContactNameValidate().setVisible(true);
		}
		if (!projectContactPhoneValid) {
		    editMerchantProfileView.getTxtProjectContactPhone().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtProjectContactPhone().getErrorMessage() != null) {
			editMerchantProfileView.getLblProjectContactPhoneValidateMessage().setValue(
				editMerchantProfileView.getTxtProjectContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutProjectContactPhoneValidate().setVisible(true);
		}
		if (!projectContactMobileValid) {
		    editMerchantProfileView.getTxtProjectContactMobile().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtProjectContactMobile().getErrorMessage() != null) {
			editMerchantProfileView.getLblProjectContactMobileValidateMessage().setValue(
				editMerchantProfileView.getTxtProjectContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutProjectContactMobileValidate().setVisible(true);
		}
		if (!projectContactEmailAddressValid) {
		    editMerchantProfileView.getTxtProjectContactEmailAddress().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtProjectContactEmailAddress().getErrorMessage() != null) {
			editMerchantProfileView.getLblProjectContactEmailAddressValidateMessage().setValue(
				editMerchantProfileView.getTxtProjectContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutProjectContactEmailAddressValidate().setVisible(true);
		}
		// operation
		if (!operationContactNameValid) {
		    editMerchantProfileView.getTxtOperationContactName().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtOperationContactName().getErrorMessage() != null) {
			editMerchantProfileView.getLblOperationContactNameValidateMessage().setValue(
				editMerchantProfileView.getTxtOperationContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutOperationContactNameValidate().setVisible(true);
		}
		if (!operationContactPhoneValid) {
		    editMerchantProfileView.getTxtOperationContactPhone().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtOperationContactPhone().getErrorMessage() != null) {
			editMerchantProfileView.getLblOperationContactPhoneValidateMessage().setValue(
				editMerchantProfileView.getTxtOperationContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutOperationContactPhoneValidate().setVisible(true);
		}
		if (!operationContactMobileValid) {
		    editMerchantProfileView.getTxtOperationContactMobile().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtOperationContactMobile().getErrorMessage() != null) {
			editMerchantProfileView.getLblOperationContactMobileValidateMessage().setValue(
				editMerchantProfileView.getTxtOperationContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutOperationContactMobileValidate().setVisible(true);
		}
		if (!operationContactEmailAddressValid) {
		    editMerchantProfileView.getTxtOperationContactEmailAddress().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtOperationContactEmailAddress().getErrorMessage() != null) {
			editMerchantProfileView.getLblOperationContactEmailAddressValidateMessage().setValue(
				editMerchantProfileView.getTxtOperationContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutOperationContactEmailAddressValidate().setVisible(true);
		}
		// technical
		if (!technicalContactNameValid) {
		    editMerchantProfileView.getTxtTechnicalContactName().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtTechnicalContactName().getErrorMessage() != null) {
			editMerchantProfileView.getLblTechnicalContactNameValidateMessage().setValue(
				editMerchantProfileView.getTxtTechnicalContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutTechnicalContactNameValidate().setVisible(true);
		}
		if (!technicalContactPhoneValid) {
		    editMerchantProfileView.getTxtTechnicalContactPhone().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtTechnicalContactPhone().getErrorMessage() != null) {
			editMerchantProfileView.getLblTechnicalContactPhoneValidateMessage().setValue(
				editMerchantProfileView.getTxtTechnicalContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutTechnicalContactPhoneValidate().setVisible(true);
		}
		if (!technicalContactMobileValid) {
		    editMerchantProfileView.getTxtTechnicalContactMobile().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtTechnicalContactMobile().getErrorMessage() != null) {
			editMerchantProfileView.getLblTechnicalContactMobileValidateMessage().setValue(
				editMerchantProfileView.getTxtTechnicalContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutTechnicalContactMobileValidate().setVisible(true);
		}
		if (!technicalContactEmailAddressValid) {
		    editMerchantProfileView.getTxtTechnicalContactEmailAddress().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtTechnicalContactEmailAddress().getErrorMessage() != null) {
			editMerchantProfileView.getLblTechnicalContactEmailAddressValidateMessage().setValue(
				editMerchantProfileView.getTxtTechnicalContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutTechnicalContactEmailAddressValidate().setVisible(true);
		}
		// financial
		if (!financialContactNameValid) {
		    editMerchantProfileView.getTxtFinancialContactName().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtFinancialContactName().getErrorMessage() != null) {
			editMerchantProfileView.getLblFinancialContactNameValidateMessage().setValue(
				editMerchantProfileView.getTxtFinancialContactName().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutFinancialContactNameValidate().setVisible(true);
		}
		if (!financialContactPhoneValid) {
		    editMerchantProfileView.getTxtFinancialContactPhone().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtFinancialContactPhone().getErrorMessage() != null) {
			editMerchantProfileView.getLblFinancialContactPhoneValidateMessage().setValue(
				editMerchantProfileView.getTxtFinancialContactPhone().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutFinancialContactPhoneValidate().setVisible(true);
		}
		if (!financialContactMobileValid) {
		    editMerchantProfileView.getTxtFinancialContactMobile().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtFinancialContactMobile().getErrorMessage() != null) {
			editMerchantProfileView.getLblFinancialContactMobileValidateMessage().setValue(
				editMerchantProfileView.getTxtFinancialContactMobile().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutFinancialContactMobileValidate().setVisible(true);
		}
		if (!financialContactEmailAddressValid) {
		    editMerchantProfileView.getTxtFinancialContactEmailAddress().addStyleName("v-textfield-error");
		    if (editMerchantProfileView.getTxtFinancialContactEmailAddress().getErrorMessage() != null) {
			editMerchantProfileView.getLblFinancialContactEmailAddressValidateMessage().setValue(
				editMerchantProfileView.getTxtFinancialContactEmailAddress().getErrorMessage().getFormattedHtmlMessage());
		    }
		    editMerchantProfileView.getLayoutFinancialContactEmailAddressValidate().setVisible(true);
		}

	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return validate;
    }
}
